package com.tl.libpay.ui;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Point;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.tl.commonlibrary.tool.DeviceUtil;

/**
 * @author JongSung
 * @Description 支付异常时展示的弹窗
 * 当支付完成后客户端会调用服务器端接口确认支付结果，若果支付结果与实际本地支付结果不一致，则弹窗处理
 * @date  2017/9/21
 */
public class PayExceptionDialog extends Dialog implements View.OnClickListener {
    private TextView sureBtn;

    private OnPayExceptionListener listener;

    public PayExceptionDialog(Context context) {
        super(context, com.tl.commonlibrary.R.style.MyDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(com.tl.commonlibrary.R.layout.dialog_pay_exception);
        Window window = getWindow();
        WindowManager manager = window.getWindowManager();
        Display display = manager.getDefaultDisplay();
        WindowManager.LayoutParams params = window.getAttributes();
        Point point = new Point();
        display.getSize(point);
//        params.height = Math.min(DeviceUtil.dp_to_px(200, getContext()), (int) (point.y * 0.5));
        params.width = Math.min(DeviceUtil.dp_to_px(300, getContext()), (int) (point.y * 2.0 / 3));
        window.setAttributes(params);
        sureBtn = (TextView) findViewById(com.tl.commonlibrary.R.id.sureBtn);
        sureBtn.setOnClickListener(this);
        setCancelable(false);
    }


    public void setListener(OnPayExceptionListener listener) {
        this.listener = listener;
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == com.tl.commonlibrary.R.id.sureBtn) {
            dismiss();
            if (listener != null) {
                listener.onSureBtnClicked(v);
            }
        }
    }

    public interface OnPayExceptionListener {
        void onSureBtnClicked(View view);
    }

}